package com.ityedao.ArrayList案例;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 上架菜品以及菜品信息浏览功能
 */
public class FoodOperator {
    // 1、定义一个ArrayList集合对象，负责存储菜品对象信息
    private ArrayList<Food> foodList = new ArrayList<>();

    // 2、上架商品功能
    public void addFood(){
        // 3、 创建一个菜品对象，封装菜品信息
        Food f = new Food();
        // 4、录入菜品信息进去
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入该菜品名称：");
        String name = sc.next();
        System.out.println("请输入该菜品价格：");
        double price = sc.nextDouble();
        System.out.println("请输入该菜品详情：");
        String desc = sc.next();

        f.setName(name);
        f.setPrice(price);
        f.setDesc(desc);
        // 5、把菜品对象存到菜品中去
        foodList.add(f);
        System.out.println("上架成功~");
    }

    /**
     * 菜品展示
     */
    public void showAllFoods(){
        if (foodList.size() == 0){
            System.out.println("一个菜品都没有~");
            return;
        }
        for (int i = 0; i < foodList.size(); i++) {
            Food food = foodList.get(i);
            System.out.println(food.getName());
            System.out.println(food.getPrice());
            System.out.println(food.getDesc());
        }
    }
    /**
     * 操作界面
     */
    public void start(){
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请选择功能：");
            System.out.println("1、菜品上架");
            System.out.println("2、展示菜品");
            System.out.println("3、退出");
            String command = sc.next();
            switch (command) {
                case "1":
                    addFood();
                    break;
                case "2":
                    showAllFoods();
                    break;
                case "3":
                    System.out.println("再见~");
                    return;
                default:
                    System.out.println("您输入的操作不存在~");
            }
        }
    }

}
